# 要记住的
# --------------------------------------------------------------------------------------------------
# 同时向文件和屏幕上输出 和 乱码
# fh = logging.FileHandler('tmp.log',encoding='utf-8')
# # fh2 = logging.FileHandler('tmp2.log',encoding='utf-8')
# sh = logging.StreamHandler()
# logging.basicConfig(
#     format='%(asctime)s - %(name)s - %(levelname)s[line :%(lineno)d]-%(module)s:  %(message)s',
#     datefmt='%Y-%m-%d %H:%M:%S %p',
#     level= logging.DEBUG,
#     # handlers=[fh,sh,fh2]
#     handlers=[fh,sh]
# )
# logging.debug('debug 信息错误 test2')
# logging.info('warning 信息错误 test2')
# logging.warning('warning message test2')
# logging.error('error message test2')
# logging.critical('critical message test2')

import time
from logging import handlers
sh = logging.StreamHandler()
rh = handlers.RotatingFileHandler('myapp.log', maxBytes=1024,backupCount=5)   # 按照大小做切割
fh = handlers.TimedRotatingFileHandler(filename='x2.log', when='s', interval=5, encoding='utf-8')
logging.basicConfig(
    format='%(asctime)s - %(name)s - %(levelname)s[line :%(lineno)d]-%(module)s:  %(message)s',
    datefmt='%Y-%m-%d %H:%M:%S %p',
    level= logging.DEBUG,
    # handlers=[fh,sh,fh2]
    handlers=[fh,rh,sh]
)